



import bpy
import 全局控制.Node.节点和插座基类.bl_节点基类 as 基类

import Core.bl_UI配色 as UI配色

import engine.initLIB.load_dll as engineLib
import ctypes







engineLib.flexCAPI.f_创建矢量分离_Vec3节点.restype = ctypes.c_bool
engineLib.flexCAPI.f_创建矢量合并_Vec3节点.restype = ctypes.c_bool
engineLib.flexCAPI.f_创建分离uVec3_Array1D节点.restype = ctypes.c_bool
engineLib.flexCAPI.f_创建合并uvec3_Array1D节点.restype = ctypes.c_bool
engineLib.flexCAPI.f_创建矢量分离_矩阵3X3节点.restype = ctypes.c_bool
engineLib.flexCAPI.f_创建矢量合并_矩阵3X3节点.restype = ctypes.c_bool




class C_Node_分离数组_f(基类.C_SN_基类):
	bl_dname = 'bl_node_分离数组'
	bl_label = '分离数组'
	
	def init(self, context):
		super(C_Node_分离数组_f, self).f_init(context)
		self.inputs.new('C_插座_List_f', name='A')
		
	def update(self):
		inNum = len(self.inputs['A'].f_getData())
		inNum = inNum - len(self.outputs)
		if inNum > 0 :
			for v in range(inNum):
				self.outputs.new('C_NodeSocket_f', name='成员:'+str(inNum+v))
				
		elif inNum < 0:
			inNum = abs(inNum)
			for v in range(inNum):
				self.outputs.remove(v)
		
	def f_update(self, 是否向下传递=False, input插座=None):
		inData = self.inputs['A'].f_getData()
		index = 0
		for v in inData:
			self.outputs[index].f_setData(v)
			index += 1

		super(C_Node_分离数组_f, self).f_update(是否向下传递, input插座)
		
class C_NODE_AddMenu_分离数组_f(bpy.types.Operator):
	bl_idname = 'node.global_node_swparate_array'
	bl_label = '分离数组'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_分离数组_f', use_transform=True)
		return {'FINISHED'}










class C_Node_分离XYZ(基类.C_Node_基类):
	bl_dname = 'bl_node_分离XYZ'
	bl_label = '分离XYZ'
	
	def init(self, context):
		super(C_Node_分离XYZ, self).f_init(context)
		self.inputs.new('C_Socket_Vec3_Array1D', name='矢量')

		self.outputs.new('C_Socket_F32_Array1D', name='x')
		self.outputs.new('C_Socket_F32_Array1D', name='y')
		self.outputs.new('C_Socket_F32_Array1D', name='z')

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

		self.f_toCPP()

	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建矢量分离_Vec3节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			self.inputs['矢量'].f_update()
		
class C_NODE_AddMenu_分离XYZ(bpy.types.Operator):
	bl_idname = 'node.global_node_swparate_xyz'
	bl_label = '分离XYZ'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_分离XYZ', use_transform=True)
		return {'FINISHED'}



class C_Node_合并XYZ(基类.C_Node_基类):
	bl_dname = 'bl_node_合并XYZ'
	bl_label = '合并XYZ'
	
	def init(self, context):
		super(C_Node_合并XYZ, self).f_init(context)

		self.inputs.new('C_Socket_F32_Array1D', name='x')
		self.inputs.new('C_Socket_F32_Array1D', name='y')
		self.inputs.new('C_Socket_F32_Array1D', name='z')

		self.outputs.new('C_Socket_Vec3_Array1D', name='矢量')

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

		self.f_toCPP()

	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建矢量合并_Vec3节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			self.inputs['x'].f_update()
			self.inputs['y'].f_update()
			self.inputs['z'].f_update()
		


class C_NODE_AddMenu_合并XYZ(bpy.types.Operator):
	bl_idname = 'node.global_node_merge_xyz'
	bl_label = '合并XYZ'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_合并XYZ', use_transform=True)
		return {'FINISHED'}
















class C_Node_分离uvec3_Array1D(基类.C_Node_基类):
	bl_dname = 'bl_node_分离uvec3_Array1D'
	bl_label = '分离uvec3_Array1D'
	
	def init(self, context):
		super(C_Node_分离uvec3_Array1D, self).f_init(context)
		self.inputs.new('C_Socket_uVec3_Array1D', name='矢量')

		self.outputs.new('C_Socket_UI32_Array1D', name='x')
		self.outputs.new('C_Socket_UI32_Array1D', name='y')
		self.outputs.new('C_Socket_UI32_Array1D', name='z')

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

		self.f_toCPP()

	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建分离uVec3_Array1D节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			self.inputs['矢量'].f_update()
		
class C_NODE_AddMenu_分离uVec3_Array1D(bpy.types.Operator):
	bl_idname = 'node.global_node_swparate_uvec_uuu'
	bl_label = '分离uvec3_Array1D'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_分离uvec3_Array1D', use_transform=True)
		return {'FINISHED'}











class C_Node_合并uvec3_Array1D(基类.C_Node_基类):
	bl_dname = 'bl_node_合并uvec3_Array1D'
	bl_label = '合并uvec3_Array1D'
	
	def init(self, context):
		super(C_Node_合并uvec3_Array1D, self).f_init(context)

		self.inputs.new('C_Socket_UI32_Array1D', name='x')
		self.inputs.new('C_Socket_UI32_Array1D', name='y')
		self.inputs.new('C_Socket_UI32_Array1D', name='z')

		self.outputs.new('C_Socket_uVec3_Array1D', name='矢量')

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

		self.f_toCPP()

	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建合并uvec3_Array1D节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			self.inputs['x'].f_update()
			self.inputs['y'].f_update()
			self.inputs['z'].f_update()
		

class C_NODE_AddMenu_合并uvec3_Array1D(bpy.types.Operator):
	bl_idname = 'node.global_node_merge_uvec_uuu'
	bl_label = '合并uvec3_Array1D'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_合并XYZ', use_transform=True)
		return {'FINISHED'}
























class C_Node_分离vec4(基类.C_Node_基类):
	bl_dname = 'bl_node_分离vec4'
	bl_label = '分离 vec4'
	
	def init(self, context):
		super(C_Node_分离vec4, self).f_init(context)
		self.inputs.new('C_Socket_Vec4_Array1D', name='矢量')
		
		self.outputs.new('C_Socket_F32_Array1D', name='x')
		self.outputs.new('C_Socket_F32_Array1D', name='y')
		self.outputs.new('C_Socket_F32_Array1D', name='z')
		self.outputs.new('C_Socket_F32_Array1D', name='w')

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

		self.f_toCPP()

	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建分离Vec4节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			self.inputs['矢量'].f_update()

class C_NODE_AddMenu_分离vec4(bpy.types.Operator):
	bl_idname = 'node.global_node_swparate_vec4'
	bl_label = '分离 vec4'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_分离vec4', use_transform=True)
		return {'FINISHED'}





class C_Node_合并vec4(基类.C_Node_基类):
	bl_dname = 'bl_node_合并vec4'
	bl_label = '合并 vec4'
	
	def init(self, context):
		super(C_Node_合并vec4, self).f_init(context)

		self.inputs.new('C_Socket_F32_Array1D', name='x')
		self.inputs.new('C_Socket_F32_Array1D', name='y')
		self.inputs.new('C_Socket_F32_Array1D', name='z')
		self.inputs.new('C_Socket_F32_Array1D', name='w')

		self.outputs.new('C_Socket_Vec4_Array1D', name='矢量')

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

		self.f_toCPP()

	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建合并vec4节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			self.inputs['x'].f_update()
			self.inputs['y'].f_update()
			self.inputs['z'].f_update()
			self.inputs['w'].f_update()
		

class C_NODE_AddMenu_合并vec4(bpy.types.Operator):
	bl_idname = 'node.global_node_merge_vec4'
	bl_label = '合并 vec4'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_合并vec4', use_transform=True)
		return {'FINISHED'}





















class C_Node_矢量分离矩阵3X3(基类.C_Node_基类):
	bl_dname = 'bl_node_矢量分离矩阵3X3'
	bl_label = '矢量分离矩阵3X3'
	
	def init(self, context):
		super(C_Node_矢量分离矩阵3X3, self).f_init(context)
		self.inputs.new('C_Socket_矩阵3X3', name='矩阵')
		
		self.outputs.new('C_Socket_Vec3', name='RA')
		self.outputs.new('C_Socket_Vec3', name='RB')
		self.outputs.new('C_Socket_Vec3', name='RC')

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色

		self.f_toCPP()

	def f_toCPP(self):
		engineLib.flexCAPI.f_创建矢量分离_矩阵3X3节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		

class C_NODE_AddMenu_元素分离矩阵3X3(bpy.types.Operator):
	bl_idname = 'node.global_node_swparate_element_matrix_3x3'
	bl_label = '元素分离矩阵3X3'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_矢量分离矩阵3X3', use_transform=True)
		return {'FINISHED'}







class C_Node_矢量合并矩阵3X3(基类.C_Node_基类):
	bl_dname = 'bl_node_矢量合并矩阵3X3'
	bl_label = '矢量合并矩阵3X3'
	
	def init(self, context):
		super(C_Node_矢量合并矩阵3X3, self).f_init(context)
		self.inputs.new('C_Socket_Vec3', name='RA')
		self.inputs.new('C_Socket_Vec3', name='RB')
		self.inputs.new('C_Socket_Vec3', name='RC')

		self.outputs.new('C_Socket_矩阵3X3', name='矩阵')
		
		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色
		
		self.f_toCPP()

	def f_toCPP(self):
		engineLib.flexCAPI.f_创建矢量合并_矩阵3X3节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		

class C_NODE_AddMenu_矢量合并矩阵3X3(bpy.types.Operator):
	bl_idname = 'node.global_node_merge_element_matrix_3x3'
	bl_label = '矢量合并矩阵3X3'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_Node_矢量合并矩阵3X3', use_transform=True)
		return {'FINISHED'}





classes = (
	C_Node_矢量分离矩阵3X3,
	C_NODE_AddMenu_元素分离矩阵3X3,

	C_Node_矢量合并矩阵3X3,
	C_NODE_AddMenu_矢量合并矩阵3X3,





	C_Node_分离数组_f,
	C_NODE_AddMenu_分离数组_f,

	C_Node_分离XYZ,
	C_NODE_AddMenu_分离XYZ,

	C_Node_合并XYZ,
	C_NODE_AddMenu_合并XYZ,


	C_Node_分离vec4,
	C_NODE_AddMenu_分离vec4,

	C_Node_合并vec4,
	C_NODE_AddMenu_合并vec4,



	C_Node_分离uvec3_Array1D,
	C_NODE_AddMenu_分离uVec3_Array1D,
	C_Node_合并uvec3_Array1D,
	C_NODE_AddMenu_合并uvec3_Array1D,
	
)


def register():
	for c in classes:
		bpy.utils.register_class(c)
		

def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)

	

